package com.money.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.money.dao.UndoLogDao;
import com.money.entity.UndoLog;
import com.money.service.UndoLogService;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class UndoLogServiceImpl extends ServiceImpl<UndoLogDao, UndoLog> implements UndoLogService {

    //保存我们xid 开始我们的事务记录
    @Override
    public void saveLogXid(String xid) {
        UndoLog undoLog = new UndoLog();
        undoLog.setXid(xid);
        undoLog.setLog_created(new Date());
        undoLog.setLog_status(1);
        undoLog.setContext("");
        undoLog.setLog_modified(new Date());
        undoLog.setRollback_info(System.currentTimeMillis());
        save(undoLog);
    }

    @Override
    public UndoLog findXid(String xid) {
        QueryWrapper<UndoLog> wrapper = new QueryWrapper<UndoLog>();
        wrapper.eq("xid", xid);
        UndoLog undoLog = getOne(wrapper);
        return undoLog;
    }

    @Override
    public void updateXid(String xid) {
        QueryWrapper<UndoLog> wrapper = new QueryWrapper<UndoLog>();
        wrapper.eq("xid", xid);
        UndoLog undoLog = new UndoLog();
        undoLog.setXid(xid);
        undoLog.setLog_modified(new Date());
        undoLog.setLog_status(0);
        update(undoLog, wrapper);
    }
}
